package com.fuqi.android.zhongcai.business.shuig.view.activity;

import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.base.view.widget.CustomProgress;
import com.fuqi.android.zhongcai.business.shuig.request.api.GetCheckInfoApi;
import com.fuqi.android.zhongcai.business.shuig.request.result.GetCheckInfoResult;
import com.fuqi.android.zhongcai.business.shuig.request.result.GetCheckInfoResult.CheckForList;
import com.fuqi.android.zhongcai.business.shuig.view.adapter.ChouCha2Adapter;
import com.fuqi.android.zhongcai.business.shuig.view.widget.BGASortableNinePhotoLayoutView;
import com.fuqi.android.zhongcai.business.shuig.view.widget.CJRow.ARResponse;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;
import com.fuqi.framework.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;

public class ChouChaShowActivity extends BaseActivity implements BGASortableNinePhotoLayoutView.Delegate{
    @Bind(R.id.lv_questionList)
    ListView mLvQuestion;
    @Bind(R.id.et_fdje)
    TextView mEtFdje;
    @Bind(R.id.et_fdyy)
    TextView mEtFdyy;
    @Bind(R.id.rl_item2)
    View mLytItem2;

    ChouCha2Adapter mQuestionAdapter;
    List<CheckForList> questionData = new ArrayList<>();

    String sQuestionList;
    String ordid;

    private BGASortableNinePhotoLayoutView ninePhotoLayout;
    private ArrayList<String> selectedPhotos = new ArrayList<>();

    Response.Listener<GetCheckInfoResult> respListener = new Response.Listener<GetCheckInfoResult>() {

        @Override
        public void onResponse(GetCheckInfoResult response) {
            CustomProgress.close();
            if (HandleCode.requestSuccess()) {
                questionData = response.getCheckList();
                mQuestionAdapter.setDate(questionData);

                mEtFdje.setText("罚单金额："+response.getPUNISH_AMOUNT());
                mEtFdyy.setText("罚单原因："+response.getPUNISH_REASON());

                if(StringUtil.parseFloat(response.getPUNISH_AMOUNT()) == 0 && StringUtil.isEmpty(response.getPUNISH_REASON())){
                    mLytItem2.setVisibility(View.GONE);
                }else{
                    mLytItem2.setVisibility(View.VISIBLE);
                }

                String path = response.getPIC_PUNISH();
                selectedPhotos = StringUtil.getListWithPath(path,",");
                ninePhotoLayout.setData(selectedPhotos);
                Log.i("juner", "juner OrderDetailResult response : " + GsonHelper.writeValue(response));
            } else {
            }
        }
    };

    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            CustomProgress.close();
            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());
        }
    };


    @Override
    public void initView() {
        titleBar.setTitle("监理抽查");
        ninePhotoLayout = (BGASortableNinePhotoLayoutView) findViewById(R.id.activity_discover_invest_publish_nine_photo);
        ninePhotoLayout.init(ChouChaShowActivity.this);
        ninePhotoLayout.setDelegate(ChouChaShowActivity.this);
    }
    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
        if(getIntent().hasExtra("response")) {
            ARResponse response = new ARResponse(getIntent().getStringExtra("response"));
            ordid = response.getValue("ORDER_ID");
        }else{
            ordid = getIntent().getStringExtra("order_id");
        }


        mQuestionAdapter = new ChouCha2Adapter(this, questionData);

        RequestManager.getInstance().call(new GetCheckInfoApi(
                new GetCheckInfoApi.GetCheckInfoParams(ordid), respListener, errorListener));

        mLvQuestion.setAdapter(mQuestionAdapter);
    }

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_choucha_show;
    }

    @Override
    public void onClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        startActivity(BGAPhotoPreviewActivity.newIntent(this, null, (ArrayList<String>) models, position));
    }

    @Override
    public boolean onLongClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        return false;
    }


}
